package rtc.core.net.rpc;

import org.json.JSONObject;

import rtc.core.net.MsgBody;

/**
 * Created by Administrator on 2018/2/23.
 */

public class RpcEntity {
    public static final int SUCCESS = 0;
    public static final int ERROR = -1;

    public static final int RPC_ERROR_TIMEOUT = 10300; //客户端请求超时
    public static final int RPC_ERROR_SEND_REQUEST = 10301; //发送RPC请求出错
    public static final int RPC_ERROR_NOT_LOGINED = 10302; //未登录
    public static final int RPC_ERROR_FN_IS_NULL = 10303; //FN参数错误
    public static final int RPC_ERROR_NETWORK_UNABLE = 10304;//网络不可用

    public interface Callback{
        void onCallback(int code,String msg,JSONObject args,RpcEntity response);
    }

    public interface Callable<T>{
        T onCall(int code,String msg,JSONObject args,RpcEntity response);
    }

    public int appid;
    public String fn;
    public int cb;

    public JSONObject reqArgs;
    public long timeout;
    public RpcEntity.Callback callback;

    public JSONObject respArgs;
    public int code = ERROR;
    public String msg;

    public RpcEntity() {
    }

    public byte[] buildRequest(){
        return new MsgBody(appid,fn,cb,reqArgs).pack();
    }

    @Override
    public String toString() {
        return "RpcEntity{" +
                "appid=" + appid +
                ", fn='" + fn + '\'' +
                ", cb=" + cb +
                ", code=" + code +
                ", msg='" + msg + '\'' +
                ", reqArgs=" + reqArgs +
                ", respArgs=" + respArgs +
                ", timeout=" + timeout +
                ", callback=" + callback +
                '}';
    }
}
